package com.atguigu.practice;

import java.util.Scanner;

public class TwoSortMethod {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        String[] strings=new String[n];
        for(int i=0;i<n;i++) {
            strings[i]=scanner.next();
        }
        //先判断是否符合长度排序
        boolean length=checkLength(strings);
        //再判断是否符合字典序排序
        boolean lexicog=checkLexicog(strings);
        //进行结果输出判断
        if(lexicog&&length){
            System.out.println("both");
            return;
        }else if(lexicog&&(!length)){
            System.out.println("lexicographically");
            return;
        }else if((!lexicog)&&(length)){
            System.out.println("lengths");
            return;
        }else{
            System.out.println("none");
        }
    }

    private static boolean checkLexicog(String[] strings) {
        for(int i=0;i< strings.length-1;i++){
            int j=i+1;
            if(!compareString(strings[i],strings[j])){
               return  false;
            }
            }
        return true;
        }

    private static boolean compareString(String string1, String string2) {
        if(string1.equals(string2)){
            return true;
        }
        int i=0;
        while(i<string1.length()&&i<string2.length()){
            char ch1=string1.charAt(i);
            char ch2=string2.charAt(i);
            if(ch1<ch2){
                return true;
            }else if(ch1==ch2){
                i++;
                continue;
            }else{
                return false;
            }
        }
        return true;
    }

    private static boolean checkLength(String[] strings) {
        for(int i=0;i< strings.length-1;i++){
            int j=i+1;
            if(strings[j].length()<strings[i].length()){
                return false;
            }
        }
        return true;
    }
}
